# 自定义过滤器
from flask import session,g
import functools



def do_index_class(index):
    if index == 1:
        return "first"
    elif index == 2:
        return "second"
    elif index == 3:
        return "third"
    else:
        return ""


# 登录成功后视图函数需要获取用户数据直接使用这个装饰器即可
def get_user_info(view_func):

    @functools.wraps(view_func)
    def wrapper(*args, **kwargs):

        # 判断用户是否登录
        # 如果查询用户数据
        user_id = session.get("user_id", None)
        user = None
        from info.models import User
        if user_id:
            # 去数据库查询用户信息
            user = User.query.get(user_id)

        g.user = user

        return view_func(*args, **kwargs)

    return  wrapper